package middleware

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"google.golang.org/grpc/metadata"
)

func RpcParams() grpc.UnaryServerInterceptor {
	return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (_ interface{}, err error) {

		md, _ := metadata.FromIncomingContext(ctx)
		fmt.Printf("Test md %v \n", md)
		fmt.Printf("UUID md %v \n", md.Get("uuid"))
		defer func() {
			if err := recover(); err != nil {
				//打印错误堆栈信息
				fmt.Println(err)
			}
		}()

		resp, err := handler(ctx, req)
		return resp, err
	}
}
